package com.oystertech.sportcms.common.result;

import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * 响应码枚举
 *
 * @author haoxr
 * @since 2020-06-23
 **/
@AllArgsConstructor
@NoArgsConstructor
public enum ResultCode implements IResultCode, Serializable {

	SUCCESS("200", "请求成功"),

	RESOURCE_NOT_FOUND("404001", "请求资源不存在"),
	INTERFACE_NOT_EXIST("404002", "接口不存在"),

	USER_LOGIN_ERROR("A0200", "用户登录异常"),
	USER_NOT_EXIST("A0201", "用户不存在"),
	USER_ACCOUNT_LOCKED("A0202", "用户账户被冻结"),
	USER_ACCOUNT_INVALID("A0203", "用户账户已作废"),

	USERNAME_OR_PASSWORD_ERROR("A0210", "用户名或密码错误"),
	PASSWORD_ENTER_EXCEED_LIMIT("A0211", "用户输入密码次数超限"),
	CLIENT_AUTHENTICATION_FAILED("A0212", "客户端认证失败"),

	VERIFY_CODE_TIMEOUT("A0213", "验证码已过期"),
	VERIFY_CODE_ERROR("A0214", "验证码错误"),

	TOKEN_INVALID("403001", "token无效或已过期"),
	TOKEN_ACCESS_FORBIDDEN("403002", "token已被禁止访问"),

	ACCESS_UNAUTHORIZED("401001", "访问未授权"),
	AUTHORIZED_ERROR("401002", "访问权限异常"),

	PARAM_ERROR("400001", "用户请求参数错误"),
	PARAM_IS_NULL("400002", "请求必填参数为空"),
	USER_ERROR("400003", "用户端错误"),
	REPEAT_SUBMIT_ERROR("400004", "您的请求已提交，请勿重复提交或等待片刻再尝试。"),

	USER_UPLOAD_FILE_ERROR("400005", "用户上传文件异常"),
	USER_UPLOAD_FILE_TYPE_NOT_MATCH("400006", "用户上传文件类型不匹配"),
	USER_UPLOAD_FILE_SIZE_EXCEEDS("400007", "用户上传文件太大"),
	USER_UPLOAD_IMAGE_SIZE_EXCEEDS("400008", "用户上传图片太大"),

	DATABASE_ERROR("500001", "数据库服务出错"),

	SYSTEM_EXECUTION_TIMEOUT("504001", "系统执行超时"),
	SYSTEM_EXECUTION_ERROR("500002", "系统执行出错"),
	SYSTEM_RESOURCE_ERROR("500003", "系统资源异常"),
	SYSTEM_RESOURCE_ACCESS_ERROR("500004", "系统资源访问异常"),

	CALL_THIRD_PARTY_SERVICE_ERROR("502001", "调用第三方服务出错"),
	MIDDLEWARE_SERVICE_ERROR("502002", "中间件服务出错"),

	UNKNOWN_ERROR("000000","未知错误");

	private String code;

	private String msg;

	@Override
	public String getCode() {
		return code;
	}

	@Override
	public String getMsg() {
		return msg;
	}

	@Override
	public String toString() {
		return "{" +
				"\"code\":\"" + code + '\"' +
				", \"msg\":\"" + msg + '\"' +
				'}';
	}

	public static ResultCode getValue(String code) {
		for (ResultCode value : values()) {
			if (value.getCode().equals(code)) {
				return value;
			}
		}
		return UNKNOWN_ERROR;
	}
}
